package com.hzit.servlet;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.hzit.entity.Classes;
import com.hzit.entity.PageResult;
import com.hzit.entity.Student;
import com.hzit.service.ClassesService;
import com.hzit.service.StudentService;
import com.hzit.service.impl.ClassesServiceImpl;
import com.hzit.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private ClassesService classesService ;
	@Override
	public void init() throws ServletException {
		classesService = new ClassesServiceImpl();
	}

	//1. 根据请求参数调用不同的处理方法
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//1.1 处理post请求的中文乱码
		req.setCharacterEncoding("UTF-8");
		//1.2 设置响应的字符集编码
		resp.setContentType("text/html;charset=utf8");
		//1.3 查询所有班级
		List<Classes> classes = classesService.findAll();
		//1.4 转换为字符串并输出
		resp.getWriter().println(JSON.toJSONString(classes));
		resp.getWriter().flush();
	}



}
